import React from 'react';
import { Router, Route,IndexRoute } from 'dva/router';
import MyLayout from './components/layout/MyLayout'

const cached = {};
function registerModel(app, model) {
  if (!cached[model.namespace]) {
    app.model(model);
    cached[model.namespace] = 1;
  }
}

const RouterConfig=function ({ history, app }) {
  const routes = [
    {
      path: '/',
      name: 'IndexPage',
      component:MyLayout,
      childRoutes: [
        <#list tables as table>
         {
          path: '/${table.className?uncap_first}',
          getComponent(nextState, cb) {
            require.ensure([], (require) => {
              registerModel(app, require("./models/${table.className}Model"));
              cb(null, require("./routes/${table.className}Route.js"));
            },'musicSong');
          },
        },
        </#list>
      ]
    }
  ];



  return <Router history={history} routes={routes} />;
}



export default RouterConfig;

